package com.cloudcc.mobile.search.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.view.activity.BeauInfoActivity;
import com.mypage.model.SearchMoreResultEntity;

/**
 * Created by zys on 2017/5/9.
 */

public class SearchMoreAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private Context context;
    private String title;
//    List<SearchMoreItem> searchmore;
    private SearchMoreResultEntity searchmore;
    public SearchMoreAdapter(Context context, SearchMoreResultEntity searchmore,String title){
        this.mInflater = LayoutInflater.from(context);
        this.context = context;
        this.searchmore = searchmore;
        this.title = title;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return searchmore.data.size()>0?searchmore.data.size():0;
    }
    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return searchmore.data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = mInflater.inflate(R.layout.search_more_item, null);
            //标题
            holder.more_title = (TextView) convertView.findViewById(R.id.search_more_name);
            //名字
            holder.tmore_name= (TextView) convertView.findViewById(R.id.search_more_value);
            holder.relativeLayout_more= (RelativeLayout) convertView.findViewById(R.id.search_more);
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.more_title.setText(title);
        holder.tmore_name.setText(searchmore.data.get(position).name);
//        //高亮显示
//        SpannableString ss = new SpannableString("abcdefgh");
//        ss.setSpan(new BackgroundColorSpan(Color.RED), 2, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//        holder.textViewlishiname.setText(ss);
        holder.relativeLayout_more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BeauInfoActivity.class);
                intent.putExtra("web",searchmore.data.get(position).id);
                context.startActivity(intent);
            }
        });

        return convertView;
    }
    class ViewHolder{
        public TextView tmore_name,more_title;
        public RelativeLayout relativeLayout_more;
    }
}

